Skip to content

Use Python for sccache hit rate computation. - #2474

Merged
AyodeAwe merged 1 commit into
NVIDIA:branch-24.12from
bdice:fix-hit-rate
Oct 21, 2024
Merged

Use Python for sccache hit rate computation.#2474
AyodeAwe merged 1 commit into
NVIDIA:branch-24.12from
bdice:fix-hit-rate

Conversation

@bdice

@bdice bdice commented Oct 21, 2024

Copy link
Copy Markdown
Contributor

Fixes an issue in CI computations of sccache hit rates. See NVIDIA/cuvs#414 for details.

@bdice
bdice requested a review from a team as a code owner October 21, 2024 19:16
@bdice
bdice requested a review from KyleFromNVIDIA October 21, 2024 19:16
@bdice bdice added bug Something isn't working non-breaking Non-breaking change labels Oct 21, 2024
@bdice bdice self-assigned this Oct 21, 2024
@AyodeAwe
AyodeAwe merged commit 714e07b into NVIDIA:branch-24.12 Oct 21, 2024

@KyleFromNVIDIA KyleFromNVIDIA left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small suggestion, you can take it or leave it. I don't need to review again.

Comment thread build.sh
COMPILE_REQUESTS=$(sccache -s | grep "Compile requests \+ [0-9]\+$" | awk '{ print $NF }')
CACHE_HITS=$(sccache -s | grep "Cache hits \+ [0-9]\+$" | awk '{ print $NF }')
HIT_RATE=$(echo - | awk "{printf \"%.2f\n\", $CACHE_HITS / $COMPILE_REQUESTS * 100}")
HIT_RATE=$(python3 -c "print(f'{${CACHE_HITS} / ${COMPILE_REQUESTS}:.2f}' if ${COMPILE_REQUESTS} else 'nan')")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For situations like this, I prefer to pass variables in as arguments, environment variables, etc. to avoid the risk of code injection. It's admittedly not a big deal in this particular situation, but I still prefer to do it.

Suggested change
HIT_RATE=$(python3 -c "print(f'{${CACHE_HITS} / ${COMPILE_REQUESTS}:.2f}' if ${COMPILE_REQUESTS} else 'nan')")
HIT_RATE=$(COMPILE_REQUESTS="${COMPILE_REQUESTS}" CACHE_HITS="${CACHE_HITS}" python3 -c "import os; print(f'{int(os.getenv(\"CACHE_HITS\")) / int(os.getenv(\"COMPILE_REQUESTS\")):.2f}' if int(os.getenv(\"COMPILE_REQUESTS\")) else 'nan')")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread build.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants